#include <math.h>
#include <iostream>
#include <fstream>
#include <string>

using std::cout;
using std::endl;
using std::ios;
using std::string;

// 预习友元的三种形式，运算符重载的三种形式，以加法运算符作为参考尝试实现重载

// 普通函数

class Point;

class Line
{
public:
    Line(const Point& A, const Point& B);
    double length() const;
private:

    Point* _A;
    Point* _B;
};

class Point
{
public:
    Point(double x = 0, double y = 0)
        : _x(x)
        , _y(y){}
    Point(const Point& rhs)
        : _x(rhs._x)
        , _y(rhs._y){}
    void print(void) const{
        cout << "(" << _x << ", " << _y << ")" << endl;
    }
friend Point operator+(const Point& lhs, const Point& rhs);
friend double Line::length() const;
friend class Line;

private:
    double _x;
    double _y;
};


int main(void)
{
    Point p1(3, 4);
    Point p2(5, 6);
    Point p3 = p1 + p2; 
    p3.print();
    Line L1(p1, p2);
    cout << L1.length() << endl;
}



Point operator+(const Point& lhs, const Point& rhs){
    return Point(lhs._x + rhs._x, lhs._y + rhs._y);
}
double Line::length() const{
    return sqrt(pow(_A->_x - _B->_x, 2) + pow(_A->_y - _B->_y, 2));
}
Line::Line(const Point& A, const Point& B)
        : _A(new Point ())
        , _B(new Point ()){
            *_A = A;
            *_B = B;
        }